package com.jsy.common.util;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Regex {
    public static void main(String[] args) {
        String str2="[ssse][123][sssgege]qwe";
        int matches = matches(str2);
        System.out.println("是否匹配："+matches);
    }

    //找出第二个中括号的数字
    private static int matches(String str) {
        String number="0";
        String regex = "(^\\[(.*?)])";//第一个中括号
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        for (int i = 0; i < 2; i++) {
            if (matcher.find()){
                number = matcher.group(2);
                System.out.println(number);
                pattern = Pattern.compile("(^\\[(\\d*)])");//第二个中括号为数字
                matcher = pattern.matcher((matcher.replaceFirst("")));
            }else {
                System.out.println("不匹配");
                return 0;
            }
        }
        return Integer.parseInt(number);
    }


}
